﻿@model SMECustomerWebsite.Models.ViewModels.DaoManager.DaoInfoViewModel
<div class="row">
    <div class="col-md-12">
        <div class="x_panel">
            <div class="x_title">
                <h2>@SMECustomerWebsite.Core.Resources.Resource.ListCreateDaoRequest.ToUpper()</h2>
                <ul class="nav navbar-right panel_toolbox">
                    <li>
                        <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                    </li>
                </ul>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                @Html.Partial("CreateDaoRequestInfo")
                @Html.Partial("PartialRejectCreateDaoRequest")
                @Html.Partial("UploadOfferLetter")
                @Html.Partial("ViewOfferLetter")
                @if (Request.Cookies[Model.CurrentUser.UserName + "CRDError"] != null)
                {
                    <div class="alert alert-danger alert-dismissible fade in" role="alert">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                        @Request.Cookies[Model.CurrentUser.UserName + "CRDError"].Value
                    </div>
                }
                else if (Request.Cookies[Model.CurrentUser.UserName + "CRDSuccess"] != null)
                {
                    <div class="alert alert-success alert-dismissible fade in" role="alert">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                        @Request.Cookies[Model.CurrentUser.UserName + "CRDSuccess"].Value
                    </div>
                }
                @if (Model.MessageType != null && Model.MessageType == Common.Type.MessageType.Error)
                {
                    <div class="alert alert-danger alert-dismissible fade in" role="alert">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                        @Model.Message
                    </div>
                }
                else if (Model.MessageType != null && Model.MessageType == Common.Type.MessageType.Success && !string.IsNullOrEmpty(Model.Message))
                {
                    <div class="alert alert-success alert-dismissible fade in" role="alert">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                        @Model.Message
                    </div>
                }
                @if (Model.CurrentUser.GroupIdentifier.Equals("1") && Model.CurrentUser.DepartmentId == 11)
                {
                    @Html.Partial("ImportResultCreateDaoRequest", "DaoManager")
                    <div class="col-md-6 cm-search-box">
                        @using (Html.BeginForm("ExportDataRequestToIT", "DaoManager", FormMethod.Post, new { @class = "sme-form-export" }))
                        {
                            <input type="submit" name="btnExportLicensing" style="width: 140px;" value="Export to excel" id="exportLicensing" class="btn btn-success right" data-toggle="tooltip" data-placement="top" title="" data-original-title="Export list of approved requests in excel to IT Division" />
                        }
                        <div class="sme-form-export">
                            <button name="btnImportLicensing" style="width: 140px;" value="Import Form" id="importResult" class="btn btn-success right" data-toggle="tooltip" data-placement="top" data-original-title="Improt result from IT Division">Import Result</button>
                        </div>
                    </div>
                }
                @switch (Model.CurrentUser.GroupIdentifier)
                {
                    case "1":
                        <table id="msbo-hr-manager" class="table custom_table table-bordered table-striped jambo_table">
                            <thead class="headings">
                                <tr>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper()</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestId.ToUpper()</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.StaffIdHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ContractType.ToUpper()</th>
                                    <th class="column-title">EMAIL</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestStatusHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CreateRequestDateHeader</th>
                                    <th class="column-title" width="10%">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                        break;
                    case "2":
                    <table id="msbo-hr-manager" class="table custom_table table-bordered table-striped jambo_table">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestId.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.StaffIdHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ContractType.ToUpper()</th>
                                <th class="column-title">EMAIL</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestStatusHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CreateRequestDateHeader</th>
                                <th class="column-title" width="10%">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    case "3":
                    <table id="msbo-hr-manager" class="table custom_table table-bordered table-striped jambo_table">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestId.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.StaffIdHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ContractType.ToUpper()</th>
                                <th class="column-title">EMAIL</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestStatusHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CreateRequestDateHeader</th>
                                <th class="column-title" width="10%">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    case "4":
                    <table id="msbo-hr-manager" class="table custom_table table-bordered table-striped jambo_table">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestId.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.StaffIdHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ContractType.ToUpper()</th>
                                <th class="column-title">EMAIL</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestStatusHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CreateRequestDateHeader</th>
                                <th class="column-title" width="10%">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    case "6":
                    <!--Modal info customer -->
                    @*@Html.Partial("ImportFormCreateDaoRequest", "DaoManager")*@

                    <!-- /modals -->
                    @*<div id="cm-search-box" class="col-md-6 cm-search-box">
                            <div class="sme-form-export">
                                <a href="DownloadForm?file=createDaoForm.xlsx" target="_blank" id="exportLicensing" class="btn btn-success right" data-toggle="tooltip" data-placement="top" title="" data-original-title="Get sample excel file">Download</a>
                            </div>
                            <div class="sme-form-export">
                                <button name="btnImportLicensing" style="width: 140px;" value="Import Form" id="importForm" class="btn btn-success right" data-toggle="tooltip" data-placement="top" data-original-title="Export list of approved requests in excel to IT Division">Import Form</button>
                            </div>
                        </div>*@
                    <table id="msbo-hr-manager" class="table custom_table table-bordered table-striped jambo_table">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestId.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.StaffIdHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ContractType.ToUpper()</th>
                                <th class="column-title">EMAIL</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestStatusHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CreateRequestDateHeader</th>
                                <th class="column-title" width="10%">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    default:
                        break;
                }
                @if (Model.CurrentUser.GroupIdentifier.AsInt() >= 3)
                {
                    <div class="ln_solid"></div>
                    <div class="form-group">
                        <div class="col-md-12 col-sm-12 col-xs-12" style=" text-align: center;">
                            @Html.ActionLink(SMECustomerWebsite.Core.Resources.Resource.AddNewBtn, "AddCreateDaoRequest", "DaoManager", new { @class = "btn btn-primary", @id = "pm-ap-cancel-btn" })
                        </div>
                    </div>
                }
            </div>
        </div>
    </div>
</div>
@section scripts
{
    <!-- Add fancyBox main JS and CSS files -->
    <script type="text/javascript" src="~/Scripts/vendors/fancyImage/jquery.fancybox.js"></script>
    <link rel="stylesheet" type="text/css" href="~/Scripts/vendors/fancyImage/jquery.fancybox.css" media="screen" />
    <script src="/scripts/tableeditable/dataTables.rowsGroup.js"></script>
    <script src="~/Scripts/custom_search_table.js"></script>
    <!-- bootstrap-daterangepicker -->
    <script src="~/scripts/datepicker/moment/moment.min.js"></script>
    <script src="~/scripts/datepicker/datepicker/daterangepicker.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            eraseCookie('@Model.CurrentUser.UserName' + 'CRDError');
            var lcColumn = [
                        { "sName": "CIF", "bSortable": true },
                        { "sName": "CIF", "bSortable": false },
                        { "sName": "NAME", "bSortable": false },
                        { "sName": "VPB INDUSTRY", "bSortable": false },
                        { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                        { "sName": "INFO", "bSortable": false }]
            var lcLenCol = 7;
            var lcCifCol = 0;
            switch (@Model.CurrentUser.GroupIdentifier) {
                case 1:
                    lcColumn = [
                            { "sName": "CIF", "bSortable": false },
                        { "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "bSortable": true },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "INFO", "bSortable": false }];
                    lcLenCol = 9;
                    lcCifCol = 2;
                    break;
                case 2:
                    lcColumn = [
                        { "sName": "CIF", "bSortable": false },
                        { "sName": "CIF", "bSortable": true },
                        { "sName": "NAME", "bSortable": false },
                        { "sName": "DATE OPEN CIF", "bSortable": false },
                        { "sName": "VPB INDUSTRY", "bSortable": false },
                        { "sName": "DATE OPEN CIF", "bSortable": false },
                        { "sName": "DATE OPEN CIF", "bSortable": false },
                        { "sName": "INFO", "bSortable": false }];
                    lcLenCol = 8;
                    lcCifCol = 1;
                    break;
                case 3:
                    if ("@Model.CurrentUser.Position"=="Hub Manager") {
                        lcColumn = [
                            { "sName": "CIF", "bSortable": true },
                            { "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "bSortable": false },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "INFO", "bSortable": false }];
                        lcLenCol = 7;
                        lcCifCol = 1;
                    }
                    break;
                default:
                    break;
            }
            var tablevip = $('#msbo-hr-manager').DataTable({
                "paging": true,
                "bServerSide": true,
                "bProcessing": true,
                "responsive": true,
                "bAutoWidth": false,
                "aLengthMenu": [10, 30, 50, 100],
                "pageLength": 10,
                "sAjaxSource": '@Url.Action("ListRequestCreateDaoData", "DaoManager")',
                "fnServerData": function (sSource, aoData, fnCallback) {
                    $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": fnCallback
                    });
                },
                "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'dataTables_wrapper'ip>>",
                "sPaginationType": "simple_numbers",//"full_numbers",
                "aoColumns": lcColumn,
                "aoColumnDefs": [{
                    "sClass": "column-title",
                    "width": "12%",
                    "aTargets": [lcLenCol],
                    "mRender": function (data, type, full) {
                        var html='<a class=\"btn btn-primary btn-xs sme_tooltip\" onclick=\"showRequestInfo(\'' + full[lcLenCol+1] + '\');\" data-toggle="tooltip" data-placement="left" title="" data-original-title="Thông tin chi tiết cán bộ bán"><i class="fa fa-info"></i></a>';
                        if (full[lcLenCol]!='') {
                            html = html + '<a class="btn btn-primary btn-xs sme_tooltip" onclick="showDocumentPicture(\'' + full[lcLenCol] + '\');" data-toggle="tooltip" data-placement="left" title="" data-original-title="Quyết định bổ nhiệm"><i class="fa fa-eye"></i></a>';
                        }else if(full[lcLenCol+3]){
                            html = html + '<a class="btn btn-info btn-xs sme_tooltip" onclick="uploadOfferLetter(\'' + full[lcLenCol+1] + '\');" data-toggle="tooltip" data-placement="left" title="" data-original-title="Upload quyết định bổ nhiệm"><i class="fa fa-cloud-upload"></i></a>';
                        }
                        if (full[lcLenCol+2]) {
                            html = html + '<a class=\"btn btn-primary btn-xs sme_tooltip\"  onclick="approved(\'' + full[lcLenCol+1] + '\');" data-toggle="tooltip" data-placement="left" title="" data-original-title="Phê duyệt yêu cầu"><i class="fa fa-check"></i></a>';
                        }
                        if (full[lcLenCol+4]) {
                            html = html + '<a class=\"btn btn-danger btn-xs sme_tooltip\"  onclick="reject(\'' + full[lcLenCol+1] + '\');" data-toggle="tooltip" data-placement="left" title="" data-original-title="Từ chối yêu cầu"><i class="fa fa-times"></i></a>';
                        }
                        return html;
                    }
                }],
                initComplete: function () {
                    this.api().columns().every(function () {
                        var column = this;
                        switch (column.context[0].aoHeader[0][column.index()].cell.innerText) {
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper())':
                                createFilterRegion(column, '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Zone)');
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.CreateRequestDateHeader)':
                                createFilterDate(column);
                                break;
                            case '@Html.Raw(@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper())':
                                createFilterBranch(column);
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.RequestStatusHeader)':
                                var option = [{ id: '-1', text: 'All' },{ id: '0', text: 'Requesting' }, { id: '1', text: 'Head of SME Branch/Hub Approved' }, { id: '2', text: 'Head of region Approved' }, { id: '3', text: 'IT Proccessing' }, { id: '4', text: 'Successfully' }, { id: '5', text: 'Rejected' }, { id: '12', text: 'Reject by user request' }, { id: '9', text: 'Head of SME Branch/Hub Rejected' }, { id: '10', text: 'Head of region Rejected' }, { id: '11', text: 'BIC Rejected' }]
                                createFilterCustType(column,option);
                                break;
                            default:
                                if (column.index() < lcLenCol) {
                                    var select = $('<input type="text" class="filtet-table">')
                                                            .appendTo($(column.header()))
                                                            .on('keyup change', function () {
                                                                column.search(this.value).draw();
                                                            });
                                }
                                break;
                        }
                    });
                },
                "drawCallback": function (settings) {
                    $(".sme_tooltip").tooltip();
                }
            });

        })

        //show document image
        function showDocumentPicture(picName) {
            $('#ifViewOfferLetter').attr('src', picName)
            $('#showOfferLetterModal').modal('show');
        };
        $('#exportLicensing').click(function () {
            location.reload();
        });

        $('#importForm').click(function () {
            $('#import_form_modal').modal('show');
        });
        $('#importResult').click(function () {
            $('#import_result_modal').modal('show');
        });
        function uploadOfferLetter(id) {
            $('#Request_Id').val(id);
            $('#upload_offer_modal').modal('show');
        }
        ////showRequestInfo
        function showRequestInfo(id) {
            $.ajax({
                url: '/DaoManager/CreateDaoRequestInfo',
                type: "POST",
                data: { id: id},
                success: function (data_response) {
                    if (data_response.fullName != null) {
                        $('#cust_info_fullname').text(data_response.fullName);
                        $('#cust_info_position').text(data_response.position);
                        $('#cust_info_staffid').text(data_response.staffId);
                        $('#cust_info_email').text(data_response.email);
                        $('#cust_info_cif').text(data_response.cif);
                        $('#cust_info_legalid').text(data_response.legalId);
                        $('#cust_info_phone').text(data_response.phone);
                        $('#cust_info_branch').text(data_response.branch);
                        $('#cust_info_DAO').text(data_response.DAO);

                    }
                    $('#showRequestInfoModal').modal('show');
                }
            })
        };

        //approve request
        function approved(id) {
            $.ajax({
                url: '@Url.Action("ApproveRequestCreateDao", "DaoManager")',
                type: "POST",
                data: { request: id},
                success: function (data_response) {
                    if (data_response.IsSuccess == true) {
                        createCookie('@Model.CurrentUser.UserName'+ 'CRDSuccess', 'Approved request successfull', 1)
                    } else {
                        createCookie('@Model.CurrentUser.UserName'+ 'CRDError', 'Approved request fail', 1)
                    }
                    location.reload();
                }
            })
        };

    </script>
    @if (Model.CurrentUser.GroupIdentifier.Equals("4") || Model.CurrentUser.GroupIdentifier.Equals("6"))
    {
        <script type="text/javascript">
            //reject request
            function reject(id) {

                $.ajax({
                    url: '@Url.Action("RejectCreateDaoRequest", "DaoManager")',
                    type: "POST",
                    data: { request: id},
                    success: function (data_response) {
                        if (data_response.IsSuccess == true) {
                            createCookie('@Model.CurrentUser.UserName'+ 'CRDSuccess', 'Reject request successfull', 1)
                        } else {
                            createCookie('@Model.CurrentUser.UserName'+ 'CRDError', 'Reject request fail', 1)
                        }
                        location.reload();
                    }
                })
            };
        </script>
    }
    else
    {
        <script type="text/javascript">
            //reject request
            function reject(id) {
                $('#Request_Id_Reject').val(id);
                $('#reject_create_dao_modal').modal('show');
            };
        </script>
    }

}